//Runtime.getRuntime().exec(commandStr)
import groovy.json.JsonSlurper 
import groovy.swing.SwingBuilder 
import javax.swing.* 
import java.awt.* 
class Command{
     def myapp = new SwingBuilder()
     
 public static void main(String[] args){ 
   def conmand=new Command()
     conmand.start()
 }
 public void start(){
  

     handle( parseJson(getAllSofts()))
    
 }
 //?????????
 public  void createFrame(Closure buttonPanel){
 
 def mainPanel = {
   myapp.panel(layout : new BorderLayout()) {
      label(text : 'soft list', horizontalAlignment : JLabel.CENTER, constraints : BorderLayout.CENTER)
      buttonPanel()
   }
 }
 
  
  def myframe = myapp.frame(title : 'eden', location : [0, 0],
   size : [2000, 100], defaultCloseOperation : WindowConstants.DISPOSE_ON_CLOSE){
      mainPanel()
   }
    
  myframe.setVisible(true)

 }
 
 
 
 //item [name:wechat, path:D:/soft/WeChat/WeChat.exe]
public  void handle(Object item){
//   item.each{
//   
//    print it.name
//    println it.path
//   }
// 

  def buttonPanel = {
   myapp.panel(constraints : BorderLayout.NORTH) {
   
        item.each{
         def soft=it
          button(text : "${soft.name}", actionPerformed : {
            exec(soft.path)
          })  
        }
   }
  }
  
  createFrame(buttonPanel)

 }
 
 public void exec(String commandStr){
 // println commandStr
  Runtime.getRuntime().exec(commandStr)
 
 }
 
 
 
 //???????????
public  Object parseJson(String s){
  def jsonSlurper = new JsonSlurper()
   def json=jsonSlurper.parseText(s)
   return json
 }
 
 //????????????????
  public  String getAllSofts(){
  return new File("F:/OSCHINA_GIT/groovy/test.txt").text
  }

}